﻿/*
 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
 */

#ifndef BURNDLG_H
#define BURNDLG_H

#include <QMainWindow>
#include <QAction>
#include <QMenu>
#include <QSettings>
#include "ChangeChip.h"
#include "DiaglogComSetting.h"
#include "SerialPort/PortManager.h"
#include "BinFileModel.h"
#include "AboutWindow.h"
#include "BurnToolCommon/StringClass.h"

class BurnCtrl;
namespace BurnDlg {
class BurnDlg : public QMainWindow {
    Q_OBJECT
public:
    explicit BurnDlg(QWidget *pParent = nullptr); // 标准构造函数
    ~BurnDlg() override;
    virtual void ResetUIAndFSM();
    virtual void ReceiveAddText(QString str);
    virtual void ReceiveClearText();
    virtual void InitBurnCtrl();
    virtual void UpdateList();
    unsigned int LoadFileConfigFromFileGetInfo(BIN_INFO &info, const QSettings &cfg, int index) const;
    void CreateNewFwpkgFile(QString burnfilePath);
    void SaveSpiltFwpkgFile(QString burnfilePath);

protected slots:
    virtual void SlotShowMenuSettings();
    virtual void SlotSettingSuccess();
    virtual void SlotBnClickedButtonSelectfile();
    virtual void SlotBnClickedButtonConn();
    virtual void SlotBnClickedButtonStartburn();
    virtual void SlotAutoDisconnect(WPARAM wParam, LPARAM lParam);
    virtual void SlotInsertPlainText(const QString &editStr);
    virtual void SlotClearPlainText();
    virtual void SlotReplacePlainText(const QString &oldText, const QString &newText);
    virtual void SlotMergeCurrentCharFormat(const QTextCharFormat &fmt);
    virtual void SlotEarseModeCurrentIndexChanged(int index);
    virtual void SlotSetProgressValue(unsigned int progress);
    virtual void SlotSetProgressRange(int min, int max);
    virtual void SlotBnClickedTableHeader(int logicalIndex);
    virtual void SlotBnClickedTableView(const QModelIndex &index);
    virtual void SlotBnDoubleClickedTableView(const QModelIndex &index);
    virtual void SlotShowChangeChip();
    void SlotChanceChipVersion(const QString &version) const;
    virtual void SlotShowAbout();
    void closeEvent(QCloseEvent *event) override;
    virtual void SlotSetEnglish();
    virtual void SlotSetChinese();
signals:
    void SignalSendMsgInBurnDlg(long int msgId, WPARAM wParam, LPARAM lParam);
protected:
    virtual bool ConfigComPort();
    void AnalyseBinFileForOne(QString path, int row);
    void changeEvent(QEvent* event) override;
    bool IsSelectOtp(IMAGE_TYPE type) const;
    int radiobtngrpBoot;
    ::BurnCtrl *burnCtrlManager[2] = {nullptr};
    ::BurnCtrl *burnCtrl;
    DiaglogComSetting *setting;
    Base::PORT_INDEX portType = Base::MIN_PORT;
    QEvent* pEvent;
    bool isAutoBurn;
    bool isLoaderDfu;
    BinFileModel* binModel;
    ChangeChip *changeChip;
    AboutWindow *aboutWin;
    ChipType chipType;
    Qt::WindowStates lastWinStates;
    bool isCheckAble;
    bool isEncrypt;
    ENCRYPT_BUFFER encryptBuffer;
    MyStringClass::StringClass stringClass;
    QAction *actEnglish;
    QAction *actChinese;
    QMenu *menuWifiLanguage;
};
}
#endif
